package com.qf.team2.netdisc.common.exception.handler;

import com.alipay.api.AlipayApiException;
import com.qf.team2.netdisc.common.exception.BusinessException;
import com.qf.team2.netdisc.common.pojo.vo.RespResultVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Simon_Wong
 * @since 2021/5/25 17:04
 */
@ControllerAdvice
public class AlipayExceptionHandler<T> {

    /**
     * 处理支付宝接口抛出的异常
     *
     * @param e 业务异常
     * @return {@link RespResultVO <T>}
     */
    @ResponseBody
    @ExceptionHandler(AlipayApiException.class)
    public RespResultVO<T> handleAlipayExceptions(AlipayApiException e) {
        System.out.println("支付宝异常");
        //todo 记录日志
        RespResultVO<T> result = new RespResultVO<>();
        result.setStatus(RespResultVO.StatusCode.BUSINESS_EXCEPTION.getValue());
        result.setMessage(e.getMessage());
        return result;
    }
}
